package com.ggs.commonconfig;

import io.swagger.v3.oas.annotations.enums.SecuritySchemeIn;
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType;
import io.swagger.v3.oas.annotations.security.SecurityScheme;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@SecurityScheme(
        name = "RawTokenAuth",  // 安全方案名称
        type = SecuritySchemeType.APIKEY,  // 使用 APIKEY 类型
        in = SecuritySchemeIn.HEADER,      // 参数位置为请求头
        paramName = "Authorization"        // 直接映射到 Authorization 头
)
public class SwaggerConfig {

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(new Info().title("API 文档").version("1.0"))
                // 全局安全要求：所有接口需要 RawTokenAuth 认证
                .addSecurityItem(new SecurityRequirement().addList("RawTokenAuth"));
    }
}